<?php

namespace app\api\controller\kami;

use app\common\controller\ApiAes;
use app\common\model\Config;

/**
 * 首页接口
 */
class Index extends ApiAes
{
    protected $noNeedLogin = ['init_config'];
    protected $noNeedRight = ['*'];

    /**
     * 获取初始化配置
     */
    public function init_config()
    {
        $list = Config::where('group', 'server_config')->select();
        if (!$list) {
            $this->error(__('No Results were found'));
        }
        // 初始化data数组
        $data = [
            'announcement' => '',
            'server_info'  => '',
            'download_url' => '',
            'kami_info'    => '',
        ];
        // 遍历list，根据name设置data对应值
        foreach ($list as $item) {
            if ($item['name'] == 'announcement') {
                $data['announcement'] = $item['value'];
            } elseif ($item['name'] == 'server_info') {
                $data['server_info'] = $item['value'];
            } elseif ($item['name'] == 'download_url') {
                $data['download_url'] = $item['value'];
            } elseif ($item['name'] == 'kami_info') {
                if ($item['value']) {
                    $data['kami_info'] = json_decode($item['value'], JSON_UNESCAPED_UNICODE);
                }
            }
        }
        $this->success(__('Success'), $data);
//        $this->success('success', $result);
    }
}
